package org.jeecg.modules.power.util.userutil;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.power.user.entity.YlUser;
import org.jeecg.modules.power.user.mapper.YlUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @BelongsProject: jeecg-boot-parent
 * @BelongsPackage: org.jeecg.modules.power.util.userutil
 * @Author: mi
 * @CreateTime: 2024-07-16 08:37
 * @Description:
 */
@Component
@Slf4j
public class MemberUserUtil {




    @Autowired
    private  YlUserMapper ylUserMapper;//用户表


    //处理会员用户过期任务task
    public void startMemberUserTask(){
        List<YlUser> userList=ylUserMapper.getTodayOverUserList();
        //添加任务
        if (userList.size()>0){
            ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
            for (YlUser user: userList) {
                long startDelay = user.getEndTime().getTime() - System.currentTimeMillis();//任务开始时间
                executor.schedule(   new Runnable() {
                                         @Override
                                         public void run() {
                                             // 执行任务的业务代码
//                                             System.out.println("执行任务==========" +
//                                                     " ，执行时间：" + DateUtils.now());
                                             ylUserMapper.updateTodayOverUser(new Date());

                                         }
                                     },     startDelay, // 执行一次
                        TimeUnit.MILLISECONDS);
            }
        }

    }






}
